<?php
require(dirname(__FILE__) .'/ucCheck.php');


Area::CheckIsOutSubmit();	// 检测是否外部提交

if (! in_array($mudi, array('checkDomain','cart'))){
	if (in_array($mudi, array('tplDel','readTplInfo','readUserMoney','domainApiRevPwd','domainDel','checkDomain','cart'))){
		$isBack = false;
	}else{
		$isBack = true;
	}
	$userRow = Users::Open('get',',UE_username,UE_state','',$judUserErr);
		if ((! $userRow) || $judUserErr != ''){
			if ($isBack){
				die('
				<br /><br />
				<center style="font-size:14px;">
					请先登录，该功能需要登录才能使用.
					'. $judUserErr .'<a class="font2_1" href="users.php?mudi=login&force=1">[登录]</a>
				</center>
				<br /><br />
				');
			}else{
				JS::AlertEnd('请先登录，该功能需要登录才能使用.');
			}
		}

	$UE_ID		= $userRow['UE_ID'];
	$UE_state	= $userRow['UE_state'];

	if ($UE_state == 0){
		if ($isBack){
			JS::AlertBackEnd('您尚未审核通过，该功能无法使用。');
		}else{
			JS::AlertEnd('您尚未审核通过，该功能无法使用。');
		}
	}
}else{
	$UE_ID = Users::UserID();
	$UE_state = 0;
}



switch ($mudi){
	case 'tplDeal':
		TplDeal();
		break;

	case 'tplDel':
		TplDel();
		break;

	case 'readTplList':
		ReadTplList();
		break;

	case 'readTplInfo':
		ReadTplInfo();
		break;

	case 'readUserMoney':
		ReadUserMoney();
		break;

	case 'domainApiLogin':
		DomainApiLogin();
		break;

	case 'domainApiRevPwd':
		DomainApiRevPwd();
		break;

	case 'domainDel':
		DomainDel();
		break;

	case 'orderDeal':
		OrderDeal();
		break;

	case 'oneDeal':
		OneDeal();
		break;

	case 'domainOut':
		DomainOut();
		break;

	case 'domainXufei':
		DomainXufei();
		break;

	case 'checkDomain':
		CheckDomain();
		break;

	case 'getBook':
		GetBook();
		break;

	case 'cart':
		Cart();
		break;

	case 'export':
		DomainExport();
		break;

	default:
		die('err');;

}

$DB->Close();





// 添加修改域名注册模板
function TplDeal(){
	global $DB,$UE_ID,$userRow;

	$backURL		= OT::PostStr('backURL');
	$dataID			= OT::PostInt('dataID');
	$userID			= OT::PostInt('userID');
	$isUpdateApi	= OT::PostInt('isUpdateApi');

	$type_old			= OT::PostStr('type_old');
	$owner_old			= OT::PostStr('owner_old');
	$owner2_old			= OT::PostStr('owner2_old');
	$lastName_old		= OT::PostStr('lastName_old');
	$lastName2_old		= OT::PostStr('lastName2_old');
	$firstName_old		= OT::PostStr('firstName_old');
	$firstName2_old		= OT::PostStr('firstName2_old');
	$prov_old			= OT::PostStr('prov_old');
	$prov2_old			= OT::PostStr('prov2_old');
	$city_old			= OT::PostStr('city_old');
	$city2_old			= OT::PostStr('city2_old');
	$addr_old			= OT::PostStr('addr_old');
	$addr2_old			= OT::PostStr('addr2_old');
	$cardType_old		= OT::PostStr('cardType_old');
	$cardNumber_old		= OT::PostStr('cardNumber_old');
	$countryCode_old	= OT::PostStr('countryCode_old');
	$postCode_old		= OT::PostStr('postCode_old');
	$phone_old			= OT::PostStr('phone_old');
	$mail_old			= OT::PostStr('mail_old');
	$fax_old			= OT::PostStr('fax_old');

	$type			= OT::PostStr('type');
	$owner			= OT::PostStr('owner');
	$owner2			= OT::PostStr('owner2');
	$lastName		= OT::PostStr('lastName');
	$lastName2		= OT::PostStr('lastName2');
	$firstName		= OT::PostStr('firstName');
	$firstName2		= OT::PostStr('firstName2');
	$prov			= OT::PostStr('prov');
	$prov2			= OT::PostStr('prov2');
	$city			= OT::PostStr('city');
	$city2			= OT::PostStr('city2');
	$addr			= OT::PostStr('addr');
	$addr2			= OT::PostStr('addr2');
	$cardType		= OT::PostStr('cardType');
	$cardNumber		= OT::PostStr('cardNumber');
	$countryCode	= OT::PostStr('countryCode');
	$postCode		= OT::PostStr('postCode');
	$phone			= OT::PostStr('phone');
	$mail			= OT::PostStr('mail');
	$fax			= OT::PostStr('fax');
	$state			= OT::PostInt('state');

	if ($owner=='' || $phone=='' || $mail==''){
		JS::AlertBackEnd('表单内容接收不全');
	}
	if ($UE_ID != $userID){
		JS::AlertBackEnd('用户ID不匹配');
	}

	$record=array();
	$record['DT_isUpdateApi']	= 0;
	$record['DT_type']			= $type;
	$record['DT_owner']			= $owner;
	$record['DT_owner2']		= $owner2;
	$record['DT_lastName']		= $lastName;
	$record['DT_lastName2']		= $lastName2;
	$record['DT_firstName']		= $firstName;
	$record['DT_firstName2']	= $firstName2;
	$record['DT_prov']			= $prov;
	$record['DT_prov2']			= $prov2;
	$record['DT_city']			= $city;
	$record['DT_city2']			= $city2;
	$record['DT_addr']			= $addr;
	$record['DT_addr2']			= $addr2;
//	$record['DT_cardType']		= $cardType;
	$record['DT_cardNumber']	= $cardNumber;
	$record['DT_countryCode']	= $countryCode;
	$record['DT_postCode']		= $postCode;
	$record['DT_phone']			= $phone;
	$record['DT_mail']			= $mail;
	$record['DT_fax']			= $fax;
//	$record['DT_state']			= $state;

	$westSysId = '';
	$addrec=$DB->query('select DT_isUpdateApi,DT_westSysId from '. OT_dbPref .'domainTpl where DT_ID='. $dataID .' and DT_userID='. $userID);
		if (! $row = $addrec->fetch()){
			$alertMode='添加';
			$record['DT_userID']	= $userID;
			$record['DT_username']	= $userRow['UE_username'];
			$judRes = $DB->InsertParam('domainTpl',$record);
		}else{
			$alertMode='修改';
			$westSysId = $row['DT_westSysId'];
			if ($row['DT_isUpdateApi'] == 1){ $isUpdateApi = 1; }
			$judRes = $DB->UpdateParam('domainTpl',$record,'DT_ID='. $dataID);
		}
	unset($addrec);

	$alertAddi = '';
	if ($judRes){
		$alertRes='成功';

		$domainSysArr = Cache::PhpFile('domainSys');
		if ($domainSysArr['DS_isWest'] == 1){
			if ($dataID == 0){ $dataID = $DB->GetOne('select max(DT_ID) from '. OT_dbPref .'domainTpl'); }

			$dataArr = array(
				'isUpdateApi'		=> $isUpdateApi,
				'westSysId'			=> $westSysId,
				'dataID'			=> $dataID,
				'userID'			=> $userID,
				'westUsername'		=> $domainSysArr['DS_westUsername'],
				'westUserpwd'		=> $domainSysArr['DS_westUserpwd'],
				'type_old'			=> $type_old,
				'owner_old'			=> $owner_old,
				'lastName_old'		=> $lastName_old,
				'firstName_old'		=> $firstName_old,
				'owner2_old'		=> $owner2_old,
				'lastName2_old'		=> $lastName2_old,
				'firstName2_old'	=> $firstName2_old,
				'countryCode_old'	=> $countryCode_old,
				'prov_old'			=> $prov_old,
				'city_old'			=> $city_old,
				'addr_old'			=> $addr_old,
				'postCode_old'		=> $postCode_old,
				'phone_old'			=> $phone_old,
				'mail_old'			=> $mail_old,
				'prov2_old'			=> $prov2_old,
				'city2_old'			=> $city2_old,
				'addr2_old'			=> $addr2_old,
				'cardNumber_old'	=> $cardNumber_old,
				'type'			=> $type,
				'owner'			=> $owner,
				'lastName'		=> $lastName,
				'firstName'		=> $firstName,
				'owner2'		=> $owner2,
				'lastName2'		=> $lastName2,
				'firstName2'	=> $firstName2,
				'countryCode'	=> $countryCode,
				'prov'			=> $prov,
				'city'			=> $city,
				'addr'			=> $addr,
				'postCode'		=> $postCode,
				'phone'			=> $phone,
				'mail'			=> $mail,
				'prov2'			=> $prov2,
				'city2'			=> $city2,
				'addr2'			=> $addr2,
				'cardNumber'	=> $cardNumber,
				);
			$retArr = AppDomainTpl::WestApiDeal($dataArr);
			$alertAddi = str_replace('西部数码','API',$retArr['note']);
		}
	}else{
		$alertRes='失败';
	}

	JS::AlertHref($alertMode . $alertRes .'！'. $alertAddi,'usersCenter.php?mudi=domainTpl');

}



// 删除域名注册模板
function TplDel(){
	global $DB,$UE_ID;

	$dataID		= OT::GetInt('dataID');

	if ($dataID<=0){
		JS::AlertEnd('指定ID错误.');
	}

	$judRes = $DB->query('delete from '. OT_dbPref .'domainTpl where DT_ID='. $dataID .' and DT_userID='. $UE_ID);
		if ($judRes){
			echo('
			<script language="javascript" type="text/javascript">
			parent.$id("data'. $dataID .'").style.display="none";
			</script>
			');
		}else{
			JS::AlertEnd('删除失败');
		}

}


// 读取域名注册模板列表
function ReadTplList(){
	global $DB,$UE_ID;

	$selID = OT::GetInt('selID');

	$chkexe = $DB->query('select DT_ID,DT_owner,DT_phone,DT_mail,DT_isUpdateApi,DT_westSysId from '. OT_dbPref .'domainTpl where DT_userID='. $UE_ID .' and DT_state=1');
	if (! $row = $chkexe->fetch()){
		die('<div class="tplItem" style="color:red;">您没有域名注册模板，请先点击【新建模板】，新建好后点击【重新加载】。</div>');
	}else{
		$count = $DB->GetOne('select count(DT_ID) from '. OT_dbPref .'domainTpl where DT_userID='. $UE_ID .' and DT_state=1');
		do{
			$apiAlert = $addiStr = $styleStr = '';
			if (strlen($row['DT_westSysId']) <= 1){
				$apiAlert = '&ensp;<span style="color:red;">（API方未有记录，请完善该模板信息）</span>';
				$addiStr = 'disabled';
				$styleStr = 'style="color:#c9c9c9;"';
			}elseif ($row['DT_isUpdateApi'] == 1){
				$apiAlert = '&ensp;<span style="color:blue;">（API方未更新，建议完善该模板信息）</span>';
			}
			echo('<div class="tplItem" '. $styleStr .'><label><input type="radio" name="tplID" value="'. $row['DT_ID'] .'" onclick="ReadTplInfo('. $row['DT_ID'] .')" '. Is::Checked($count==1 ? $row['DT_ID'] : $selID,$row['DT_ID']) .' '. $addiStr .' />'. $row['DT_owner'] .'，'. $row['DT_phone'] .'，'. $row['DT_mail'] . $apiAlert .'</label></div>');
		}while ($row = $chkexe->fetch());
	}
	unset($chkexe);
}


// 读取域名注册模板信息
function ReadTplInfo(){
	global $DB,$UE_ID;

	$dataID		= OT::GetInt('dataID');

	$chkexe = $DB->query('select * from '. OT_dbPref .'domainTpl where DT_ID='. $dataID .' and DT_userID='. $UE_ID);
	if (! $row = $chkexe->fetch()){
		JS::AlertEnd('搜索不到该注册模板信息，请刷新页面试试。');
	}else{
		/*
		echo('
		$id("type'. ($row['DT_type']=='个人'?0:1) .'").checked = true;
		$id("owner").value = "'. $row['DT_owner'] .'";
		$id("lastName").value = "'. $row['DT_lastName'] .'";
		$id("firstName").value = "'. $row['DT_firstName'] .'";
		$id("prov").value = "'. $row['DT_prov'] .'";
		$id("city").value = "'. $row['DT_city'] .'";
		$id("addr").value = "'. $row['DT_addr'] .'";
		$id("cardNumber").value = "'. $row['DT_cardNumber'] .'";
		$id("countryCode").value = "'. $row['DT_countryCode'] .'";
		$id("postCode").value = "'. $row['DT_postCode'] .'";
		$id("phone").value = "'. $row['DT_phone'] .'";
		$id("mail").value = "'. $row['DT_mail'] .'";
		$id("fax").value = "'. $row['DT_fax'] .'";
		$id("owner2").value = "'. $row['DT_owner2'] .'";
		$id("lastName2").value = "'. $row['DT_lastName2'] .'";
		$id("firstName2").value = "'. $row['DT_firstName2'] .'";
		$id("prov2").value = "'. $row['DT_prov2'] .'";
		$id("city2").value = "'. $row['DT_city2'] .'";
		$id("addr2").value = "'. $row['DT_addr2'] .'";
		');
		*/
		echo('
		$id("tplBox").style.display = "";
		$id("type").innerHTML = "'. $row['DT_type'] .'";
		$id("owner").innerHTML = "'. $row['DT_owner'] .'";
		$id("lastName").innerHTML = "'. $row['DT_lastName'] .'";
		$id("firstName").innerHTML = "'. $row['DT_firstName'] .'";
		$id("prov").innerHTML = "'. $row['DT_prov'] .'";
		$id("city").innerHTML = "'. $row['DT_city'] .'";
		$id("addr").innerHTML = "'. $row['DT_addr'] .'";
		$id("cardNumber").innerHTML = "'. $row['DT_cardNumber'] .'";
		$id("countryCode").innerHTML = "'. $row['DT_countryCode'] .'";
		$id("postCode").innerHTML = "'. $row['DT_postCode'] .'";
		$id("phone").innerHTML = "'. $row['DT_phone'] .'";
		$id("mail").innerHTML = "'. $row['DT_mail'] .'";
		$id("fax").innerHTML = "'. $row['DT_fax'] .'";
		$id("owner2").innerHTML = "'. $row['DT_owner2'] .'";
		$id("lastName2").innerHTML = "'. $row['DT_lastName2'] .'";
		$id("firstName2").innerHTML = "'. $row['DT_firstName2'] .'";
		$id("prov2").innerHTML = "'. $row['DT_prov2'] .'";
		$id("city2").innerHTML = "'. $row['DT_city2'] .'";
		$id("addr2").innerHTML = "'. $row['DT_addr2'] .'";
		');
	}
	unset($chkexe);
}


// 读取用户金额
function ReadUserMoney(){
	global $DB,$UE_ID;

	$userMoney = $DB->GetOne('select UE_money from '. OT_dbPref .'users where UE_ID='. $UE_ID);
	echo('
	$id("userMoney").innerHTML = "'. $userMoney .'";
	');
}


function DomainApiLogin(){
	global $DB,$UE_ID;

	$dataID		= OT::GetInt('dataID');
	
	AppDomain::PanelLogin($dataID, $UE_ID);
}


function domainApiRevPwd(){
	global $DB,$UE_ID;

	$dataID		= OT::GetInt('dataID');
	
	$showexe=$DB->query('select DD_apiID,DD_domain,DD_pwd from '. OT_dbPref .'domainData where DD_ID='. $dataID .' and DD_userID='. $UE_ID);
	if (! $row = $showexe->fetch()){ JS::AlertCloseEnd('指定ID或用户ID错误'); }

	$newPwd = OT::RndChar(8);
	$resArr = AppIdcDomain::RevPwd(array('apiID'=>$row['DD_apiID'], 'domain'=>$row['DD_domain'], 'pwd'=>$newPwd));
	if (! $resArr['res']){
		JS::AlertEnd('重置密码失败，原因：'. $resArr['note'] .'。');
	}else{
		$result = $DB->UpdateParam('domainData', array('DD_pwd'=>Encrypt::SyEnDe('en',$newPwd)), 'DD_ID='. $dataID);
		if ($result){
			die('
			$id("domainPwdBox'. $dataID .'").innerHTML = "'. $newPwd .'";
			$id("domainPwdBtn'. $dataID .'").innerHTML = "<span style=\'color:green;\'>重置成功</span>";
			');
		}else{
			JS::AlertEnd('重置密码成功，但更新信息失败，请记住新密码（'. $newPwd .'）联系管理员。');
		}
	}
	unset($row,$showexe);
}


// 删除未注册成功的域名
function DomainDel(){
	global $DB,$UE_ID;

	$dataID		= OT::GetInt('dataID');

	if ($dataID<=0){ JS::AlertEnd('指定ID错误.'); }

	$chkexe = $DB->query('select DD_domain,DD_state from '. OT_dbPref .'domainData where DD_ID='. $dataID .' and DD_userID='. $UE_ID);
	if ($row = $chkexe->fetch()){
		if ($row['DD_state'] == 1){
			JS::AlertEnd('该域名（'. $row['DD_domain'] .'）状态正常，不允许做删除操作.');
		}
	}else{
		JS::AlertEnd('域名指定ID错误.');
	}
	unset($chkexe);

	$judRes = $DB->query('delete from '. OT_dbPref .'domainData where DD_ID='. $dataID);
		if ($judRes){
			echo('
			<script language="javascript" type="text/javascript">
			parent.$id("data'. $dataID .'").style.display="none";
			</script>
			');
		}else{
			JS::AlertEnd('删除失败');
		}

}



// 域名注册表单提交
function OrderDeal(){
	global $DB,$UE_ID,$userRow;

	$userID		= $UE_ID;
	$username	= $userRow['UE_username'];
	$tplID		= OT::PostInt('tplID');
	$payMode	= OT::PostStr('payMode');
	$isPay		= OT::PostInt('isPay');
	$sel		= OT::Post('sel');
	$selCount	= count($sel);
		if ($tplID==0 || $payMode==''){
			JS::AlertBackEnd('表单信息接收不全。');
		}
		if (is_array($sel)==false || $selCount == 0){
			JS::AlertBackEnd('表单接收不到域名信息。');
		}

		$westSysId = $DB->GetOne('select DT_westSysId from '. OT_dbPref .'domainTpl where DT_ID='. $tplID);
		if (strlen($westSysId) <= 2){
			JS::AlertHrefEnd('API方没有该注册模板信息，请先更新注册模板或者打钩[强制更新API信息]','usersCenter.php?mudi=domainTplRev&dataID='. $tplID);
		}

	$domainSysArr = Cache::PhpFile('domainSys');
	if ($domainSysArr['DS_isReg'] == 0){
		JS::AlertHrefEnd('域名注册暂时关闭，如果有问题，请联系网站管理员或客服。','usersCenter.php?mudi=domainManage');
	}

	ini_set('max_execution_time', 0);
	set_time_limit(0); 
	@ob_end_clean();
	ob_implicit_flush(1);
	ob_start();

	echo('
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<div style="font-size:14px;">
	<div style="margin-top:8px;font-weight:bold;">域名注册 处理中...</div>
	');

	$oneRunNum = 1;	// 直接批量运行最大数量
	$infoArr = array();
	$infoNum = 0;
	foreach ($sel as $val){
		$infoNum ++;
		$domainId	= OT::PostInt('domainId'. $val);
		$cartId		= OT::PostInt('cartId'. $val);
		$name		= OT::PostStr('name'. $val);
		$ext		= OT::PostStr('ext'. $val);
		$priceID	= OT::PostInt('price'. $val);
		$year		= OT::PostInt('price'. $val .'_year'. $priceID);
		$price		= OT::PostFloat('price'. $val .'_year'. $year .'_'. $priceID);

		if ($priceID==0 || $year==0 || $price<1 || $name=='' || $ext==''){
			OrderShowItem($infoNum .'、'. $name .'.'. $ext .'   <span style="color:red;">信息异常（'. $priceID .'|'. $year .'|'. $price .'），不做操作</span>'); continue;

		}elseif ($domainId > 0){
			$chkexe = $DB->query('select DD_domain,DD_userID,DD_state from '. OT_dbPref .'domainData where DD_ID='. $domainId);
			if ($row = $chkexe->fetch()){
				if ($row['DD_state'] == 1){
					OrderShowItem($infoNum .'、'. $name .'.'. $ext .'   <span style="color:red;">该域名（'. $row['DD_domain'] .'）状态正常，不需要再注册.</span>'); continue;
				}
				if ($row['DD_userID'] != $userID){
					OrderShowItem($infoNum .'、'. $name .'.'. $ext .'   <span style="color:red;">该域名（'. $row['DD_domain'] .'）记录不是你的，您无权注册.</span>'); continue;
				}
			}else{
				OrderShowItem($infoNum .'、'. $name .'.'. $ext .'   <span style="color:red;">该域名（'. $row['DD_domain'] .'）指定ID错误.</span>'); continue;
			}
			unset($chkexe);

		}elseif (AppIdcDomain::IsReg($name, $ext) == 0){
			OrderShowItem($infoNum .'、'. $name .'.'. $ext .'   <span style="color:red;">已被注册.</span>'); continue;

		}

		OrderShowItem($infoNum .'、'. $name .'.'. $ext .'   <span id="'. $name . $ext .'">等待处理中，请稍等...</span>');
		$infoArr[] = array(
			'domainId'	=> $domainId,
			'cartId'	=> $cartId,
			'domain'	=> $name .'.'. $ext,
			'name'		=> $name,
			'ext'		=> $ext,
			'year'		=> $year,
			'priceID'	=> $priceID,
			'price'		=> $price,
			);
		ob_flush();
		flush();
	}

	$domainCount = count($infoArr);
	if ($isPay == 1 && $domainCount > $oneRunNum){
		// AJAX运行
		$cartStr = '';
		for ($i=0; $i<$domainCount; $i++){
			if ($infoArr[$i]['cartId'] > 0){
				$res = $DB->UpdateParam('domainCart', array('DC_isBuy'=>1, 'DC_dataArr'=>serialize($infoArr[$i])), 'DC_ID='. $infoArr[$i]['cartId']);
			}else{
				$paraArr = array(
					'DC_time'	=> TimeDate::Get(),
					'DC_userID'		=> $userID,
					'DC_theme'		=> $infoArr[$i]['domain'],
					'DC_name'		=> $infoArr[$i]['name'],
					'DC_ext'		=> $infoArr[$i]['ext'],
					'DC_isBuy'		=> 1,
					'DC_dataArr'	=> serialize($infoArr[$i])
					);
				$res = $DB->InsertParam('domainCart', $paraArr, 'DC_ID='. $infoArr[$i]['cartId']);
					if ($res){
						$infoArr[$i]['cartId'] = $DB->GetOne('select max(DC_ID) from '. OT_dbPref .'domainCart where DC_userID='. $userID .' and DC_isBuy=1');
					}
			}
			$cartStr .= '<input type="hidden" id="cart'. $i .'" name="cart'. $i .'" value="'. $infoArr[$i]['cartId'] .'" />';
		}
		echo(
			$cartStr .'
			<input type="hidden" id="cartCount" name="cartCount" value="'. $domainCount .'" />
			<input type="hidden" id="tplID" name="tplID" value="'. $tplID .'" />
			<input type="hidden" id="payMode" name="payMode" value="'. $payMode .'" />
			<div id="resBox"></div>
			<link href="template/share.css?v='. OT_VERSION .'" rel="stylesheet" type="text/css">
			<script language="javascript" type="text/javascript" src="js/inc/jquery.min.js?v='. OT_VERSION .'"></script>
			<script language="javascript" type="text/javascript" src="js/inc/common.js?v='. OT_VERSION .'"></script>
			<script language="javascript" type="text/javascript" src="js/app/domain.js?v='. OT_VERSION .'"></script>
			<script language="javascript" type="text/javascript">
			RunMoreReg();
			</script>
			');
	}else{
		// 直接运行批量注册
		$succNum = 0;
		foreach ($infoArr as $item){
			$alertStr = '';
			$domainPwd = OT::RndChar(8);
			$record = array();
			$record['DD_time']		= TimeDate::Get();
			$record['DD_userID']	= $userID;
			$record['DD_tplID']		= $tplID;
			$record['DD_priceID']	= $item['priceID'];
			$record['DD_ext']		= $item['ext'];
			$record['DD_domain']	= $item['domain'];
			$record['DD_pwd']		= Encrypt::SyEnDe('en',$domainPwd);
			if ($isPay == 1){
				$priceexe = $DB->query('select DP_apiID,DP_ext,DP_firstPrice,DP_secondPrice,DP_isLock from '. OT_dbPref .'domainPrice where DP_ID='. $item['priceID']);
				if (! $row = $priceexe->fetch()){
					OrderShowJs($item['name'] . $item['ext'], '<span style="color:red;">搜索不到该域名后缀价格.</span>'); continue;
				}
				if ($row['DP_ext'] != $item['ext']){
					OrderShowJs($item['name'] . $item['ext'], '<span style="color:red;">搜索该域名后缀ID与实际后缀不符。</span>'); continue;
				}
				$userPrice = floatval($row['DP_firstPrice']) + floatval($row['DP_secondPrice'])*($item['year']-1);
				if ( OT::FloatCmp($userPrice, $item['price']) != 0 ){
					OrderShowJs($item['name'] . $item['ext'], '<span style="color:red;">查询到域名'. $item['year'] .'年价格与表单信息不符（'. $userPrice .'≠'. $item['price'] .'）</span>'); continue;
				}
				$apiID = $row['DP_apiID'];
				$isLock= $row['DP_isLock'];
				$priceexe = null;

				$userMoney = floatval($DB->GetOne('select UE_money from '. OT_dbPref .'users where UE_ID='. $userID));
					if ( OT::FloatCmp($userMoney, $userPrice) < 0){
						OrderEndItem('用户余额'. $userMoney .'元，扣款'. $userPrice .'元，余额不足，没法扣款，操作停止。');
					}
				$result = $DB->UpdateParam('users',array('UE_money'=>'UE_money-'. $userPrice,'UE_payMoney'=>'UE_payMoney+'. $userPrice),'UE_ID='. $userID);
				if (! $result){
					OrderEndItem('用户余额扣款失败，操作停止。');
				}

				$alertHead = '注册并付款';
				$record['DD_apiID']		= $apiID;

				$alertStr = '\n用户金额 '. $userMoney .' 元，扣款 '. $userPrice .' 元，剩余 '. OT::NumFormat($userMoney - $userPrice) .' 元';
			}else{
				$alertHead = '预注册暂不付款';
				$record['DD_state']	= 0;
			}

			if ($item['domainId'] > 0){
				$result = $DB->UpdateParam('domainData', $record, 'DD_ID='. $item['domainId']);
			}else{
				$result = $DB->InsertParam('domainData', $record);
			}

			if ($result){
				$alertRes='成功';
				OrderShowJs($item['name'] . $item['ext'], '<span style="color:blue;">数据保存中...</span>');
				if ($item['domainId'] > 0){
					$dataID = $item['domainId'];
				}else{
					$dataID = $DB->GetOne('select max(DD_ID) from '. OT_dbPref .'domainData where DD_userID='. $userID);
				}

				if ($isPay == 1){
					$domainArr = array();
					$domainArr['apiID']		= $row['DP_apiID'];
					$domainArr['tplID']		= $tplID;
					$domainArr['westSysId']	= $westSysId;
					$domainArr['userID']	= $userID;
					$domainArr['dataID']	= $dataID;
					$domainArr['ext']		= $item['ext'];
					$domainArr['domain']	= $item['domain'];
					$domainArr['domainPwd']	= $domainPwd;
					$domainArr['year']		= $item['year'];
					$domainArr['money']		= $isLock == 0 ? 388 : $userPrice;
					$resArr = AppIdcDomain::Reg($domainArr);
					// print_r($resArr);die();
					if (! $resArr['res']){
						$vpsSysArr = Cache::PhpFile('vpsSys');
						if (strpos($vpsSysArr['VS_failMoneyStr'],'|domainReg|') !== false){
							$DB->UpdateParam('users',array('UE_money'=>'UE_money+'. $userPrice,'UE_payMoney'=>'UE_payMoney-'. $userPrice),'UE_ID='. $userID);
							$MR_money = 0;
							$MR_remMoney = $userMoney;
							$noteStr = '，不扣款';
						}else{
							$MR_money = $userPrice*(-1);
							$MR_remMoney = $userMoney - $userPrice;
							$noteStr = '，已扣款，请联系管理员处理';
						}
						$DB->UpdateParam('domainData',array('DD_state'=>-1, 'DD_stateNote'=>$resArr['ori']),'DD_ID='. $dataID);
						$scoreArr = array();
						$scoreArr['MR_userID']		= $userID;
						$scoreArr['MR_username']	= $username;
						$scoreArr['MR_dataID']		= $dataID;
						$scoreArr['MR_dataName']	= $item['domain'];
						$scoreArr['MR_type']		= 'domain';
						$scoreArr['MR_type2']		= '注册';
						$scoreArr['MR_money']		= $MR_money;
						$scoreArr['MR_remMoney']	= $MR_remMoney;
						$scoreArr['MR_bank']		= '账户余额';
						$scoreArr['MR_note']		= '注册域名失败'. $noteStr .'！域名：'. $item['domain'] .'；付款方式：'. AppDomain::PayMode($payMode) .'；'. $item['year'] .'年价格：'. $userPrice .'元；';
						$scoreArr['MR_adminID']		= 0;
						$scoreArr['MR_adminName']	= '';
						AppMoneyRecord::AddData($scoreArr);

						AreaApp::MessageSend('regDomain0', '『失败』会员“'. $username .'”域名注册失败['. $item['domain'] .']'. $noteStr .'。【'. TimeDate::Get() .'】');

						OrderShowJs($item['name'] . $item['ext'], '注册失败，原因：'. str_replace('"','“',$resArr['note']) .'。'); continue;
					}else{
						$succNum ++;
						$startDate = TimeDate::Get('date');
						$endDate = TimeDate::Add('y',$item['year'],$startDate);
						$dataArr = array();
						$dataArr['DD_type']			= $resArr['type'];
						$dataArr['DD_owner']		= $resArr['owner'];
						$dataArr['DD_startDate']	= $startDate;
						$dataArr['DD_endDate']		= $endDate;
						$dataArr['DD_state']		= 1;
						$dataArr['DD_stateNote']	= $resArr['ori'];
						if ($resArr['type'] == 'jingan'){
							$dataArr['DD_type2']	= $resArr['type2'];
							$dataArr['DD_pwd']		= Encrypt::SyEnDe('en',$resArr['note']['domainPwd']);
							$dataArr['DD_orderId']	= $resArr['note']['orderId'];
							$dataArr['DD_workId']	= $resArr['note']['busiId'];
						}
						$DB->UpdateParam('domainData', $dataArr, 'DD_ID='. $dataID);
						if ($item['cartId'] > 0){
							$DB->Delete('domainCart','DC_ID='. $item['cartId']);
						}

						AreaApp::MessageSend('regDomain1', '会员“'. $username .'”域名注册成功['. $item['domain'] .']。【'. TimeDate::Get() .'】');

						OrderShowJs($item['name'] . $item['ext'], '<span style="color:green;">注册成功！</span>账户余额：'. $userMoney .' - '. $userPrice .' = <span style="color:blue;">'. ($userMoney - $userPrice) .'</span>');
					}

					$scoreArr = array();
					$scoreArr['MR_userID']		= $userID;
					$scoreArr['MR_username']	= $username;
					$scoreArr['MR_dataID']		= $dataID;
					$scoreArr['MR_dataName']	= $item['domain'];
					$scoreArr['MR_type']		= 'domain';
					$scoreArr['MR_type2']		= '注册';
					$scoreArr['MR_money']		= $userPrice*(-1);
					$scoreArr['MR_remMoney']	= $userMoney - $userPrice;
					$scoreArr['MR_bank']		= '账户余额';
					$scoreArr['MR_note']		= '注册域名！域名：'. $item['domain'] .'；付款方式：'. AppDomain::PayMode($payMode) .'；'. $item['year'] .'年价格：'. $userPrice .'元；';
					$scoreArr['MR_adminID']		= 0;
					$scoreArr['MR_adminName']	= '';
					$mrRes = AppMoneyRecord::AddData($scoreArr);
						if (! $mrRes){ $alertStr .= '\n财务信息记录失败（需要“财务基础包”插件支持）！'; }
				}
			}else{
				$alertRes='失败';
			}
			ob_flush();
			flush();
		}

		if ($isPay == 1){
			OrderShowItem('<br />处理完毕！注册域名共 '. $selCount .' 个，注册成功 <span style="color:red;">'. $succNum .'</span> 个。点击返回<a href="usersCenter.php?mudi=domainManage" style="color:blue;">【域名管理】</a> 或 <a href="domain.html" style="color:blue;">【域名注册】</a>');
		}else{
			JS::AlertHref($alertHead . $alertRes .'！'. $alertStr,'usersCenter.php?mudi=domainManage');
		}

	}

	echo('
	</div>
	');

}



// 多个域名时，单个域名提交处理
function OneDeal(){
	global $DB,$UE_ID,$userRow;

	$userID		= $UE_ID;
	$username	= $userRow['UE_username'];
	$dataID		= OT::GetInt('dataID');
	$tplID		= OT::GetInt('tplID');
	$payMode	= OT::GetStr('payMode');
	$currCart	= OT::GetInt('currCart');

	$domainSysArr = Cache::PhpFile('domainSys');
	if ($domainSysArr['DS_isReg'] == 0){
		JS::AlertHrefEnd('域名注册暂时关闭，如果有问题，请联系网站管理员或客服。','usersCenter.php?mudi=domainManage');
	}

	ini_set('max_execution_time', 0);
	set_time_limit(0); 

	if ($dataID <= 0){
		JS::AlertEnd('购物车ID错误。');
	}
	if ($tplID <= 0){
		JS::AlertEnd('注册模板ID错误。');
	}

	$loadexe = $DB->query('select DC_userID,DC_isBuy,DC_dataArr from '. OT_dbPref .'domainCart where DC_ID='. $dataID .' and DC_userID='. $userID .' and DC_isBuy=1');
	if (! $row = $loadexe->fetch()){
		JS::AlertEnd('购物车里找不到该域名记录。');
	}
	$item = unserialize($row['DC_dataArr']);
	unset($loadexe);

	$alertStr = '';
	$domainPwd = OT::RndChar(8);
	$record = array();
	$record['DD_time']		= TimeDate::Get();
	$record['DD_userID']	= $userID;
	$record['DD_tplID']		= $tplID;
	$record['DD_priceID']	= $item['priceID'];
	$record['DD_ext']		= $item['ext'];
	$record['DD_domain']	= $item['domain'];
	$record['DD_pwd']		= Encrypt::SyEnDe('en',$domainPwd);

	$priceexe = $DB->query('select DP_apiID,DP_ext,DP_firstPrice,DP_secondPrice,DP_isLock from '. OT_dbPref .'domainPrice where DP_ID='. $item['priceID']);
	if (! $row = $priceexe->fetch()){
		OrderShowJs($item['name'] . $item['ext'], '<span style="color:red;">搜索不到该域名后缀价格.</span>'); die();
	}
	if ($row['DP_ext'] != $item['ext']){
		OrderShowJs($item['name'] . $item['ext'], '<span style="color:red;">搜索该域名后缀ID与实际后缀不符。</span>'); die();
	}
	$userPrice = floatval($row['DP_firstPrice']) + floatval($row['DP_secondPrice'])*($item['year']-1);
	if ( OT::FloatCmp($userPrice, $item['price']) != 0 ){
		OrderShowJs($item['name'] . $item['ext'], '<span style="color:red;">查询到域名'. $item['year'] .'年价格与表单信息不符（'. $userPrice .'≠'. $item['price'] .'）</span>'); die();
	}
	$apiID = $row['DP_apiID'];
	$isLock= $row['DP_isLock'];
	$priceexe = null;

	$westSysId = $DB->GetOne('select DT_westSysId from '. OT_dbPref .'domainTpl where DT_ID='. $tplID);
	if (strlen($westSysId) <= 2){
		JS::AlertHrefEnd('API方没有该注册模板信息，请先更新注册模板或者打钩[强制更新API信息]','usersCenter.php?mudi=domainTplRev&dataID='. $tplID);
	}

	$userMoney = floatval($DB->GetOne('select UE_money from '. OT_dbPref .'users where UE_ID='. $userID));
		if ( OT::FloatCmp($userMoney, $userPrice) < 0){
			OrderEndItem('用户余额'. $userMoney .'元，扣款'. $userPrice .'元，余额不足，没法扣款，操作停止。');
		}
	$result = $DB->UpdateParam('users',array('UE_money'=>'UE_money-'. $userPrice,'UE_payMoney'=>'UE_payMoney+'. $userPrice),'UE_ID='. $userID);
	if (! $result){
		OrderEndItem('用户余额扣款失败，操作停止。');
	}

	$alertHead = '注册并付款';
	$record['DD_apiID']		= $apiID;

	$alertStr = '\n用户金额 '. $userMoney .' 元，扣款 '. $userPrice .' 元，剩余 '. OT::NumFormat($userMoney - $userPrice) .' 元';

	if ($item['domainId'] > 0){
		$result = $DB->UpdateParam('domainData', $record, 'DD_ID='. $item['domainId']);
	}else{
		$result = $DB->InsertParam('domainData', $record);
	}

	if ($result){
		OrderShowJs($item['name'] . $item['ext'], '<span style="color:blue;">数据保存中...</span>');
		if ($item['domainId'] > 0){
			$dataID = $item['domainId'];
		}else{
			$dataID = $DB->GetOne('select max(DD_ID) from '. OT_dbPref .'domainData where DD_userID='. $userID);
		}

		$domainArr = array();
		$domainArr['apiID']		= $row['DP_apiID'];
		$domainArr['tplID']		= $tplID;
		$domainArr['westSysId']	= $westSysId;
		$domainArr['userID']	= $userID;
		$domainArr['dataID']	= $dataID;
		$domainArr['ext']		= $item['ext'];
		$domainArr['domain']	= $item['domain'];
		$domainArr['domainPwd']	= $domainPwd;
		$domainArr['year']		= $item['year'];
		$domainArr['money']		= $isLock == 0 ? 388 : $userPrice;
		$resArr = AppIdcDomain::Reg($domainArr);
		// print_r($resArr);die();
		if (! $resArr['res']){
			$vpsSysArr = Cache::PhpFile('vpsSys');
			if (strpos($vpsSysArr['VS_failMoneyStr'],'|domainReg|') !== false){
				$DB->UpdateParam('users',array('UE_money'=>'UE_money+'. $userPrice,'UE_payMoney'=>'UE_payMoney-'. $userPrice),'UE_ID='. $userID);
				$MR_money = 0;
				$MR_remMoney = $userMoney;
				$noteStr = '，不扣款';
			}else{
				$MR_money = $userPrice*(-1);
				$MR_remMoney = $userMoney - $userPrice;
				$noteStr = '，已扣款，请联系管理员处理';
			}
			$DB->UpdateParam('domainData',array('DD_state'=>-1, 'DD_stateNote'=>$resArr['ori']),'DD_ID='. $dataID);
			$scoreArr = array();
			$scoreArr['MR_userID']		= $userID;
			$scoreArr['MR_username']	= $username;
			$scoreArr['MR_dataID']		= $dataID;
			$scoreArr['MR_dataName']	= $item['domain'];
			$scoreArr['MR_type']		= 'domain';
			$scoreArr['MR_type2']		= '注册';
			$scoreArr['MR_money']		= $MR_money;
			$scoreArr['MR_remMoney']	= $MR_remMoney;
			$scoreArr['MR_bank']		= '账户余额';
			$scoreArr['MR_note']		= '注册域名失败'. $noteStr .'！域名：'. $item['domain'] .'；付款方式：'. AppDomain::PayMode($payMode) .'；'. $item['year'] .'年价格：'. $userPrice .'元；';
			$scoreArr['MR_adminID']		= 0;
			$scoreArr['MR_adminName']	= '';
			AppMoneyRecord::AddData($scoreArr);

			AreaApp::MessageSend('regDomain0', '『失败』会员“'. $username .'”域名注册失败['. $item['domain'] .']'. $noteStr .'。【'. TimeDate::Get() .'】');

			OrderShowJs($item['name'] . $item['ext'], '注册失败，原因：'. str_replace('"','“',$resArr['note']) .'。');
		}else{
			$startDate = TimeDate::Get('date');
			$endDate = TimeDate::Add('y',$item['year'],$startDate);
			$dataArr = array();
			$dataArr['DD_type']			= $resArr['type'];
			$dataArr['DD_owner']		= $resArr['owner'];
			$dataArr['DD_startDate']	= $startDate;
			$dataArr['DD_endDate']		= $endDate;
			$dataArr['DD_state']		= 1;
			$dataArr['DD_stateNote']	= $resArr['ori'];
			if ($resArr['type'] == 'jingan'){
				$dataArr['DD_type2']	= $resArr['type2'];
				$dataArr['DD_pwd']		= Encrypt::SyEnDe('en',$resArr['note']['domainPwd']);
				$dataArr['DD_orderId']	= $resArr['note']['orderId'];
				$dataArr['DD_workId']	= $resArr['note']['busiId'];
			}
			$DB->UpdateParam('domainData', $dataArr, 'DD_ID='. $dataID);
			if ($item['cartId'] > 0){
				$DB->Delete('domainCart','DC_ID='. $item['cartId']);
			}

			AreaApp::MessageSend('regDomain1', '会员“'. $username .'”域名注册成功['. $item['domain'] .']。【'. TimeDate::Get() .'】');

			OrderShowJs($item['name'] . $item['ext'], '<span style="color:green;">注册成功！</span>账户余额：'. $userMoney .' - '. $userPrice .' = <span style="color:blue;">'. ($userMoney - $userPrice) .'</span>');
			JS::Diy('succCart ++;');

			$scoreArr = array();
			$scoreArr['MR_userID']		= $userID;
			$scoreArr['MR_username']	= $username;
			$scoreArr['MR_dataID']		= $dataID;
			$scoreArr['MR_dataName']	= $item['domain'];
			$scoreArr['MR_type']		= 'domain';
			$scoreArr['MR_type2']		= '注册';
			$scoreArr['MR_money']		= $userPrice*(-1);
			$scoreArr['MR_remMoney']	= $userMoney - $userPrice;
			$scoreArr['MR_bank']		= '账户余额';
			$scoreArr['MR_note']		= '注册域名！域名：'. $item['domain'] .'；付款方式：'. AppDomain::PayMode($payMode) .'；'. $item['year'] .'年价格：'. $userPrice .'元；';
			$scoreArr['MR_adminID']		= 0;
			$scoreArr['MR_adminName']	= '';
			$mrRes = AppMoneyRecord::AddData($scoreArr);
				if (! $mrRes){ $alertStr .= '\n财务信息记录失败（需要“财务基础包”插件支持）！'; }
		}

		if ($currCart > 3){
			JS::DiyEnd('ShowMengceng("正在排队请求等候中...",6);setTimeout("RunMoreReg()",6000);');
		}else{
			// JS::DiyEnd('RunMoreReg();');
			JS::DiyEnd('setTimeout("RunMoreReg()",1000);');
		}
	}else{
		JS::AlertEnd('保存信息失败');
	}

}


function OrderEndItem($str){
	die('<div style="margin-top:8px;">'. $str .'&ensp;&ensp;点击返回<a href="usersCenter.php?mudi=domainManage" style="color:blue;">【域名管理】</a> 或 <a href="domain.html" style="color:blue;">【域名注册】</a></div>');
}

function OrderShowItem($str){
	echo('<div style="margin-top:8px;">'. $str .'</div>');
}

function OrderShowJs($id, $str){
	echo('
	<script language="javascript" type="text/javascript">
	document.getElementById("'. $id .'").innerHTML="'. str_replace('"','\"',$str) .'";
	</script>
	');
}


// 域名转出
function DomainOut(){
	global $DB,$UE_ID,$userRow;

	$userID = $UE_ID;
	$username = $userRow['UE_username'];

	$dealType	= OT::PostStr('dealType');
	$dealID		= OT::PostInt('dealID');
		if ($dealID <= 0){ JS::AlertEnd('该记录ID错误.'); }

	$chkexe = $DB->query('select DD_type,DD_domain,DD_endDate,DD_state from '. OT_dbPref .'domainData where DD_ID='. $dealID .' and DD_userID='. $userID);
		if (! $row = $chkexe->fetch()){
			JS::AlertEnd('域名不存在或者不属于您.');
		}
		$type	= $row['DD_type'];
		$domain	= $row['DD_domain'];
		/*
		if (TimeDate::Diff('d',$row['DD_endDate'],TimeDate::Get('date') >= 30){
			JS::AlertBackEnd('该域名已过期超过30天，无法做续费操作.');
		}
		*/

	$dataArr = array('domain'=>$domain);

	$domainSysArr = Cache::PhpFile('domainSys');

	if ($type == 'west'){
		ApiWest2::$user = $domainSysArr['DS_westUsername'];
		ApiWest2::$passwd = Encrypt::SyEnDe('de',$domainSysArr['DS_westUserpwd']);
		switch ($dealType){
			case 'apply':
				if ($row['DD_state'] != 1){
					JS::AlertEnd('该域名（'. $domain .'）状态不正常，无法做申请转出操作.');
				}

				$retArr = ApiWest2::DomainZhuanchuApply( $dataArr );
					if ($retArr['result'] == 200 || empty($retArr)){
						$DB->UpdateParam('domainData', array('DD_state'=>11, 'DD_stateTime'=>TimeDate::Get()), 'DD_ID='. $dealID .' and DD_state=1');
						JS::Diy('
							$id("state'. $dealID .'").value=\'11\';
							$id("stateStr'. $dealID .'").innerHTML=\''. AppDomain::StateCN(11) .'\';
							$id("funcStr'. $dealID .'").innerHTML=\'<span style="color:green;">申请转出成功</span>\';
							');
						// JS::AlertEnd('域名（'. $domain .'）申请转出成功.');
					}else{
						JS::AlertEnd('域名（'. $domain .'）申请转出失败，原因['. $retArr['errcode'] .']：'. $retArr['msg']);
					}
				break;

			case 'sendPwd':
				if ($row['DD_state'] != 11){
					JS::AlertEnd('该域名（'. $domain .'）状态不是 申请转出，无法做重发密码操作.');
				}

				$retArr = ApiWest2::DomainZhuanchuSendPwd( $dataArr );
					if ($retArr['result'] == 200 || empty($retArr)){
						JS::Diy('
							$id("funcStr'. $dealID .'").innerHTML=\'<span style="color:green;">重发密码成功</span>\';
							');
						// JS::AlertEnd('域名（'. $domain .'）重发密码成功.');
					}else{
						JS::AlertEnd('域名（'. $domain .'）重发密码失败，原因['. $retArr['errcode'] .']：'. $retArr['msg']);
					}
				break;

			case 'refresh':
				$retArr = ApiWest2::DomainZhuanchuRefresh( $dataArr );
					if ($retArr['result'] == 200){
						$alertStr = '';
						switch ($retArr['errcode']){
							case 100:	// 对方还未转入
								$alertStr = '对方还未转入.';
								if ($row['DD_state'] == 1){
									$DB->UpdateParam('domainData', array('DD_state'=>11), 'DD_ID='. $dealID .' and DD_state=1');
								}
								JS::Diy('
									$id("funcStr'. $dealID .'").innerHTML=\'对方还未转入\';
									');
								break;

							case 300:	// 正在转出中
								$alertStr = '正在转出中';
								$DB->UpdateParam('domainData', array('DD_state'=>12), 'DD_ID='. $dealID .' and DD_state=11');
								JS::Diy('
									$id("state'. $dealID .'").value=\'12\';
									$id("stateStr'. $dealID .'").innerHTML=\''. AppDomain::StateCN(12) .'\';
									$id("funcStr'. $dealID .'").innerHTML=\'<input type="button" onclick="DomainZhuanchu(`agree`,'. $dealID .');" value="同意转出" />\';
									');
								break;

							case 200:	// 已经转出
								$alertStr = '已经转出';
								$DB->UpdateParam('domainData', array('DD_state'=>13), 'DD_ID='. $dealID .' and DD_state in (11,12)');
								JS::Diy('
									$id("state'. $dealID .'").value=\'13\';
									$id("stateStr'. $dealID .'").innerHTML=\''. AppDomain::StateCN(13) .'\';
									$id("funcStr'. $dealID .'").innerHTML=\'<span style="color:#a59ea3;">转出已处理</span>\';
									');
								break;

							case 500:	// 不支持查询
								$alertStr = '不支持查询，请联系管理员处理.';
								JS::Diy('
									$id("funcStr'. $dealID .'").innerHTML=\'<span style="color:red;">不支持查询</span>\';
									');
								break;

							case 600:	// 不确定状态
								$alertStr = '不确定状态，请联系管理员处理.';
								JS::Diy('
									$id("funcStr'. $dealID .'").innerHTML=\'<span style="color:red;">不确定状态</span>\';
									');
								break;

							default :
								$alertStr = '异常错误['. $retArr['errcode'] .']，请联系管理员处理.';
								JS::Diy('
									$id("funcStr'. $dealID .'").innerHTML=\'<span style="color:red;">异常错误['. $retArr['errcode'] .']</span>\';
									');
								break;
						}

						// JS::AlertEnd('域名（'. $domain .'）刷新状态成功，'. $alertStr);
					}else{
						JS::Diy('
							$id("funcStr'. $dealID .'").innerHTML=\'<span style="color:red;">原因['. $retArr['errcode'] .']：'. $retArr['msg'] .'</span>\';
							');
						// JS::AlertEnd('域名（'. $domain .'）刷新状态失败，原因['. $retArr['errcode'] .']：'. $retArr['msg']);
					}
				break;

			case 'cancel':
				$retArr = ApiWest2::DomainZhuanchuCancel( $dataArr );
					if ($retArr['result'] == 200){
						$DB->UpdateParam('domainData', array('DD_state'=>1), 'DD_ID='. $dealID .' and DD_state in (11,12)');
						JS::Diy('
							$id("state'. $dealID .'").value=\'1\';
							$id("stateStr'. $dealID .'").innerHTML=\''. AppDomain::StateCN(1) .'\';
							$id("funcStr'. $dealID .'").innerHTML=\'<span style="color:#a59ea3;">撤销转出成功</span>\';
							');
						// JS::AlertEnd('域名（'. $domain .'）撤销转出成功.');
					}else{
						JS::AlertEnd('域名（'. $domain .'）撤销转出失败，原因['. $retArr['errcode'] .']：'. $retArr['msg']);
					}
				break;

			case 'agree':
				$retArr = ApiWest2::DomainZhuanchuAgree( $dataArr );
					if ($retArr['result'] == 200 || empty($retArr)){
						$DB->UpdateParam('domainData', array('DD_state'=>13), 'DD_ID='. $dealID .' and DD_state in (11,12)');
						JS::Diy('
							$id("state'. $dealID .'").value=\'13\';
							$id("stateStr'. $dealID .'").innerHTML=\''. AppDomain::StateCN(13) .'\';
							$id("funcStr'. $dealID .'").innerHTML=\'<span style="color:#a59ea3;">同意转出成功</span>\';
							');
						// JS::AlertEnd('域名（'. $domain .'）同意转出成功.');
					}else{
						JS::Diy('
							$id("funcStr'. $dealID .'").innerHTML=\'<span style="color:red;">同意转出失败，原因['. $retArr['errcode'] .']：'. $retArr['msg'] .'</span>\';
							');
						// JS::AlertEnd('域名（'. $domain .'）同意转出失败，原因['. $retArr['errcode'] .']：'. $retArr['msg']);
					}
				break;

			default :
				JS::AlertEnd('操作类型（'. $dealType .'）不明确.');
				break;
		}
	}else{
		JS::AlertEnd('该域名（'. $domain .'）暂不支持转出操作（'. $type .'）.');
	}

}


// 域名续费
function DomainXufei(){
	global $DB,$UE_ID,$userRow;

	$userID = $UE_ID;
	$username = $userRow['UE_username'];
	$payMode = 'userMoney';
	$backURL	= OT::PostStr('backURL');
	$dataID		= OT::PostInt('dataID');
	$year		= OT::PostInt('payYear');
	// $userPrice	= OT::PostFloat('userPrice');
	$userPrice	= OT::PostFloat('year'. $year .'Price');
		if ($dataID <= 0){ JS::AlertBackEnd('该记录ID错误.'); }
		if ($userPrice == 0){ JS::AlertBackEnd('扣款金额不能为0。'); }

	$chkexe = $DB->query('select DD_priceID,DD_workId,DD_ext,DD_domain,DD_endDate,DD_state from '. OT_dbPref .'domainData where DD_ID='. $dataID .' and DD_userID='. $userID);
	if (! $row = $chkexe->fetch()){
		JS::AlertBackEnd('域名指定ID错误.');
	}
	$domain = $row['DD_domain'];
	if ($row['DD_state'] != 1){
		JS::AlertBackEnd('该域名（'. $domain .'）状态不正常，无法做续费操作.');
	}
/*	if (TimeDate::Diff('d',$row['DD_endDate'],TimeDate::Get('date') >= 30){
		JS::AlertBackEnd('该域名已过期超过30天，无法做续费操作.');
	} */

	$priceexe = $DB->query('select DP_secondPrice,DP_ext,DP_apiID from '. OT_dbPref .'domainPrice where DP_ID='. $row['DD_priceID']);
	if (! $rs = $priceexe->fetch()){
		JS::AlertBackEnd('找不到该域名指定的价格信息.');
	}
	if ($rs['DP_ext'] != $row['DD_ext']){
		JS::AlertBackEnd('搜索该域名后缀价格记录与实际后缀不符，请刷新下页面，重新操作下。');
	}
	$payMoney = floatval($rs['DP_secondPrice'])*$year;
	if ( OT::FloatCmp($payMoney, $userPrice) != 0 ){
		JS::AlertBackEnd('查询到域名'. $year .'年价格与表单信息不符（'. $userPrice .'≠'. $payMoney .'），请刷新下页面，重新操作下。');
	}

	$userMoney = floatval($DB->GetOne('select UE_money from '. OT_dbPref .'users where UE_ID='. $userID));
		if ( OT::FloatCmp($userMoney, $userPrice) < 0){
			JS::AlertBackEnd('用户余额'. $userMoney .'元，扣款'. $userPrice .'元，余额不足，没法扣款。');
		}
	$result = $DB->UpdateParam('users',array('UE_money'=>'UE_money-'. $userPrice,'UE_payMoney'=>'UE_payMoney+'. $userPrice),'UE_ID='. $userID);
	if (! $result){
		JS::AlertBackEnd('用户余额扣款失败，请刷新页面重试下。');
	}

	$alertStr = '\n用户金额 '. $userMoney .' 元，扣款 '. $userPrice .' 元，剩余 '. OT::NumFormat($userMoney - $userPrice) .' 元';

	$domainArr = array();
	$domainArr['apiID']		= $rs['DP_apiID'];
	$domainArr['domain']	= $domain;
	$domainArr['endDate']	= $row['DD_endDate'];
	$domainArr['workId']	= $row['DD_workId'];
	$domainArr['year']		= $year;
	$domainArr['money']		= $userPrice;
	$resArr = AppIdcDomain::Xufei($domainArr);
	if (! $resArr['res']){
		$vpsSysArr = Cache::PhpFile('vpsSys');
		if (strpos($vpsSysArr['VS_failMoneyStr'],'|domainXufei|') !== false){
			$DB->UpdateParam('users',array('UE_money'=>'UE_money+'. $userPrice,'UE_payMoney'=>'UE_payMoney-'. $userPrice),'UE_ID='. $userID);
			$MR_money = 0;
			$MR_remMoney = $userMoney;
			$noteStr = '，不扣款';
		}else{
			$MR_money = $userPrice*(-1);
			$MR_remMoney = $userMoney - $userPrice;
			$noteStr = '，已扣款，请联系管理员处理';
		}
		$DB->UpdateParam('domainData',array('DD_state2'=>11, 'DD_stateNote'=>$resArr['ori']),'DD_ID='. $dataID);
		$scoreArr = array();
		$scoreArr['MR_userID']		= $userID;
		$scoreArr['MR_username']	= $username;
		$scoreArr['MR_dataID']		= $dataID;
		$scoreArr['MR_dataName']	= $domain;
		$scoreArr['MR_type']		= 'domain';
		$scoreArr['MR_type2']		= '续费';
		$scoreArr['MR_money']		= $MR_money;
		$scoreArr['MR_remMoney']	= $MR_remMoney;
		$scoreArr['MR_bank']		= '账户余额';
		$scoreArr['MR_note']		= '域名续费失败'. $noteStr .'！域名：'. $domain .'；付款方式：'. AppDomain::PayMode($payMode) .'；'. $year .'年价格：'. $userPrice .'元；';
		$scoreArr['MR_adminID']		= 0;
		$scoreArr['MR_adminName']	= '';
		AppMoneyRecord::AddData($scoreArr);

		AreaApp::MessageSend('xufeiDomain0', '『失败』会员“'. $username .'”域名续费失败['. $domain .']'. $noteStr .'。【'. TimeDate::Get() .'】');

		JS::AlertBackEnd('续费失败，原因：'. $resArr['note'] .'。');
	}else{
		$endDate = TimeDate::Add('y',$year,$row['DD_endDate']);
		$dataArr = array();
		$dataArr['DD_endDate']		= $endDate;
		$dataArr['DD_state']		= 1;
		$dataArr['DD_state2']		= 0;
		$dataArr['DD_stateNote']	= $resArr['ori'];
		$DB->UpdateParam('domainData', $dataArr, 'DD_ID='. $dataID);

		$scoreArr = array();
		$scoreArr['MR_userID']		= $userID;
		$scoreArr['MR_username']	= $username;
		$scoreArr['MR_dataID']		= $dataID;
		$scoreArr['MR_dataName']	= $domain;
		$scoreArr['MR_type']		= 'domain';
		$scoreArr['MR_type2']		= '续费';
		$scoreArr['MR_money']		= $userPrice*(-1);
		$scoreArr['MR_remMoney']	= $userMoney - $userPrice;
		$scoreArr['MR_bank']		= '账户余额';
		$scoreArr['MR_note']		= '域名续费！域名：'. $domain .'；付款方式：'. AppDomain::PayMode($payMode) .'；'. $year .'年价格：'. $userPrice .'元；';
		$scoreArr['MR_adminID']		= 0;
		$scoreArr['MR_adminName']	= '';
		$mrRes = AppMoneyRecord::AddData($scoreArr);
			if (! $mrRes){ $alertStr .= '\n财务信息记录失败（需要“财务基础包”插件支持）！'; }

		AreaApp::MessageSend('xufeiDomain1', '会员“'. $username .'”域名续费成功['. $domain .']。【'. TimeDate::Get() .'】');

		JS::AlertHref('续费成功！'. $alertStr,'usersCenter.php?mudi=domainManage');
	}

}


// 检查域名
function CheckDomain(){
	global $DB;

	$domainStr	= OT::GetStr('domainStr');
	$nameStr	= OT::GetStr('nameStr');
	$extStr		= OT::GetStr('extStr');
	$nameArr	= explode('|', $nameStr);
	$extArr		= explode('|', $extStr);
	$count	= count($nameArr);

	ini_set('max_execution_time', 0);
	set_time_limit(0); 
	@ob_end_clean();
	ob_implicit_flush(1);
	ob_start();

	$domainSysArr = Cache::PhpFile('domainSys');

	for ($i=0; $i<$count; $i++){
		if (strlen($nameArr[$i]) > 0){
			$state = AppIdcDomain::IsReg($nameArr[$i], $extArr[$i]);
			if ($state == 1 || $extArr[$i] == 'test'){
				$ext = Str::RegExp($extArr[$i],'sql+.');
				$chkexe = $DB->query('select DP_firstPrice,DP_secondPrice from '. OT_dbPref .'domainPrice where DP_apiID='. $domainSysArr['DS_priceApiID'] .' and DP_firstPrice>=1 and DP_ext='. $DB->ForStr($ext) .' order by DP_firstPrice ASC limit 1');
				if ($row = $chkexe->fetch()){
					$priceStr = $row['DP_firstPrice'] .'元/首年，'. $row['DP_secondPrice'] .'元/续费';
				}else{
					$priceStr = '';
				}
				unset($chkexe);

				echo('
				<script language="javascript" type="text/javascript">
				parent.$id("domainState'. $i .'").innerHTML = \'<span class="ok">（尚未注册）</span>\';
				parent.$id("domainCont'. $i .'").innerHTML = \'<span class="ce">'. $priceStr .'</span><a href="####" onclick=\\\'AddCart("'. $nameArr[$i] .'","'. $extArr[$i] .'");return false;\\\' class="btn btn-add add-list">加入购物车</a>\';
				</script>
				');

			}elseif ($state == 0){
				echo('
				<script language="javascript" type="text/javascript">
				parent.$id("domainState'. $i .'").innerHTML = \'<span class="failure">（已被注册）</span>\';
				parent.$id("domainCont'. $i .'").innerHTML = \'<a href="http://'. $nameArr[$i] .'.'. $extArr[$i] .'/" target="_blank">[浏览该网站]</a>&ensp;<a href="domainWhois.php?domain='. $nameArr[$i] .'.'. $extArr[$i] .'" target="_blank">[查询whois信息]</a>\';
				</script>
				');

			}else{
				echo('
				<script language="javascript" type="text/javascript">
				parent.$id("domainState'. $i .'").innerHTML = \'<span class="failure" style="color:red;">（查询失败）</span>\';
				parent.$id("domainCont'. $i .'").innerHTML = \'<a href="http://'. $nameArr[$i] .'.'. $extArr[$i] .'/" target="_blank">[浏览该网站]</a>&ensp;<a href="domainWhois.php?domain='. $nameArr[$i] .'.'. $extArr[$i] .'" target="_blank">[查询whois信息]</a>\';
				</script>
				');

			}
			ob_flush();
			flush();		
		}
	}

}


// 获取域名证书
function GetBook(){
	global $DB,$UE_ID;

	$dataID = OT::GetInt('dataID');
	
	AppDomain::GetBook($dataID);
}


// 域名购物车
function Cart(){
	global $DB,$UE_ID;

	$mudi2	= OT::GetStr('mudi2');

	if ($UE_ID == 0){
		if ($mudi2 != 'read'){ echo('alert("请先会员登录，才能使用域名购物车功能。");'); }
		die('
		$id("cartNum").innerHTML = \'\';
		$id("userDomainList").innerHTML = \'<div style="padding:15px;text-height:center;color:#999;font-size:16px;"><i class="fa fa-cart-plus" style="font-size:45px;"></i>&ensp;会员登录后，才能使用和显示清单。<div style="padding-top:6px;margin:0 auto;text-align:center;"><a class="font2_1" href="users.php?mudi=login&force=1">[会员登录]</a> / <a class="font2_1" href="users.php?mudi=reg&force=1">[会员注册]</a></div></div>\';
		');
	}

	if ($mudi2 == 'add'){
		$name	= OT::GetStr('name','sql');
		$ext	= OT::GetRegExpStr('ext','sql+.');

		$chkexe = $DB->query('select DC_ID from '. OT_dbPref .'domainCart where DC_userID='. $UE_ID .' and DC_theme='. $DB->ForStr($name .'.'. $ext));
		if ($chkexe->fetch()){
			die('alert("该域名（'. $name .'.'. $ext .'）已在购物车里，无需重复加入。");');
		}
		unset($chkexe);

		$doNum = $DB->GetOne('select count(DC_ID) from '. OT_dbPref .'domainCart where DC_userID='. $UE_ID);
		if ($doNum >= 200){
			die('alert("购物车域名数量达到200上限，请先结算付款注册后再添加要注册的域名。");');
		}

		$record = array();
		$record['DC_time']		= TimeDate::Get();
		$record['DC_userID']	= $UE_ID;
		$record['DC_theme']		= $name .'.'. $ext;
		$record['DC_name']		= $name;
		$record['DC_ext']		= $ext;
		$judRes = $DB->InsertParam('domainCart',$record);
			if ($judRes){
				$alertRes='成功';
			}else{
				$alertRes='失败';
				die('alert("该域名（'. $name .'.'. $ext .'）加入购物车失败，请刷新页面重新操作下。");');
			}

	}elseif ($mudi2 == 'del'){
		$dataID	= OT::GetStr('dataID');

		$judRes = $DB->Delete('domainCart','DC_ID='. $dataID .' and DC_userID='. $UE_ID);
		$alertRes='成功';

	}elseif ($mudi2 == 'clear'){
		$judRes = $DB->Delete('domainCart','DC_userID='. $UE_ID);
		$alertRes='成功';

	}elseif ($mudi2 == 'read'){
		$alertRes='成功';

	}

	if ($alertRes == '成功'){
		$loadexe = $DB->query('select DC_ID,DC_theme from '. OT_dbPref .'domainCart where DC_userID='. $UE_ID);
		if ($row = $loadexe->fetch()){
			$num = 0;
			$retStr = '<ul style="max-height:230px;overflow-y:auto;">';
			do{
				$num ++;
				$retStr .= '<li title="'. $row['DC_theme'] .'" style="padding:2px 0 0 10px;"><i class="fa fa-times right pointer" style="padding:8px 10px 0 0;" onclick="DelCart('. $row['DC_ID'] .')"></i><span>'. $row['DC_theme'] .'</span></li>';
			}while ($row = $loadexe->fetch());
			$numStr = '（<span style="color:red;">'. $num .'</span>）';
			$retStr .= '<li style="display:none;"></li></ul>'.
				'<div class="pointer right" style="margin:25px 10px 0 0;color:blue;" onclick="ClearCart()">[清空购物车]</div><input type="button" style="margin:10px 0 0 10px;padding:2px 15px;" class="newBtn1 red" value="确定结算" onclick="BuyCart()" />';
		}else{
			$numStr = '';
			$retStr = '<div style="padding:15px;text-height:center;color:#999;font-size:16px;"><i class="fa fa-cart-plus" style="font-size:45px;"></i>&ensp;暂无域名记录</div>';
		}
		unset($loadexe);
		die('
		$id("cartNum").innerHTML = \''. $numStr .'\';
		$id("userDomainList").innerHTML = \''. $retStr .'\';
		');
	}
}


// 域名导出
function DomainExport(){
	global $DB,$userRow;

	$exportExt		= OT::PostStr('exportExt');
		if (! in_array($exportExt, array('xls','txt'))){ $exportExt = 'txt'; }
	$refDomain		= OT::PostRegExpStr('refDomain','sql+.');
	$refDate1		= OT::PostStr('refDate1');
		if (! strtotime($refDate1)){ $refDate1=''; }
	$refDate2		= OT::PostStr('refDate2');
		if (! strtotime($refDate2)){ $refDate2=''; }
	$refEndDate1	= OT::PostStr('refEndDate1');
		if (! strtotime($refEndDate1)){ $refEndDate1=''; }
	$refEndDate2	= OT::PostStr('refEndDate2');
		if (! strtotime($refEndDate2)){ $refEndDate2=''; }

	$SQLstr='select DD_time,DD_domain,DD_startDate,DD_endDate,DD_pwd,DD_owner,DD_note,DD_state,DD_state2 from '. OT_dbPref .'domainData where DD_userID='. $userRow['UE_ID'];

	$searStr = '';
	if ($refDomain != ''){ $SQLstr .= " and DD_domain like '%". $DB->ForStr($refDomain,false) ."%'"; $searStr .= '域名：'. $refDomain .'；'; }
	if ($refDate1 != ''){ $SQLstr .= ' and DD_startDate>='. $DB->ForTime($refDate1); $searStr .= '开通时间头：'. $refDate1 .'；'; }
	if ($refDate2 != ''){ $SQLstr .= ' and DD_startDate<'. $DB->ForTime(TimeDate::Add('d',1,$refDate2)); $searStr .= '开通时间尾：'. $refDate2 .'；'; }
	if ($refEndDate1 != ''){ $SQLstr .= ' and DD_endDate>='. $DB->ForTime($refEndDate1); $searStr .= '到期时间头：'. $refEndDate1 .'；'; }
	if ($refEndDate2 != ''){ $SQLstr .= ' and DD_endDate<'. $DB->ForTime(TimeDate::Add('d',1,$refEndDate2)); $searStr .= '到期时间尾：'. $refEndDate2 .'；'; }
	if (strlen($searStr) > 0){ $searStr = '，搜索条件【'. $searStr .'】'; }

	$retStr = '';
	$recordNum = 0;
	$loadexe = $DB->query($SQLstr .' order by DD_startDate ASC');
		if (! $row = $loadexe->fetch()){
			JS::AlertCloseEnd('没有搜索到记录，无需导出.');
		}

	$filename = $userRow['UE_username'] .'域名记录_'. TimeDate::Get('datetimeStr') .'.'. $exportExt;
	$ua = $_SERVER['HTTP_USER_AGENT'];
	$encoded_filename = urlencode($filename);
	$encoded_filename = str_replace('+', '%20', $encoded_filename);
	if (preg_match('/MSIE/', $ua)) {
		header('Content-Disposition: attachment; filename="'. $encoded_filename .'"');
	} else if (preg_match("/Firefox/", $ua)) {
		header('Content-Disposition: attachment; filename*="utf8\'\''. $filename .'"');
	} else {
		header('Content-Disposition: attachment; filename="'. $filename .'"');
	}

	if ($exportExt == 'xls'){
		header('Content-Type: application/vnd.ms-excel; name="excel"');
		header('Content-type: application/octet-stream');
		header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
		header('Pragma: no-cache');
		header('Expires: 0');

		$retStr = '
			<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
			<head>
				<meta http-equiv=Content-Type content="text/html; charset=utf-8">
			</head>
			<body style="font-size:14px; font-family:simsun,"Microsoft YaHei";">
			<table border="1" style="border-color: #c9c9c9;"><head>'. $filename .'</head>
			<tr><td>编号</td><td>域名</td><td>所有者</td><td>注册日期</td><td>到期日期</td><td>状态</td><td>添加时间</td></tr>
			'; 

		do {
			$recordNum ++;
			$retStr .= '<tr><td>'. $recordNum .'</td><td>'. $row['DD_domain'] .'</td><td>'. $row['DD_owner'] .'</td><td>'. $row['DD_startDate'] .'</td><td>'. $row['DD_endDate'] .'</td><td>'. AppDomain::StateCN($row['DD_state'],$row['DD_endDate']) .'</td><td>'. $row['DD_time'] .'</td></tr>';
		}while ($row = $loadexe->fetch());

		$retStr .= '
			</table>
			<div>共导出'. $recordNum .'条域名记录'. $searStr .'</div>
			</body>
			</html>
			';

		echo($retStr);

	}else{
		header('Content-Type: text/plain');

		do {
			$retStr .= $row['DD_domain'] . PHP_EOL;
			$recordNum ++;
		}while ($row = $loadexe->fetch());
		unset($loadexe);

		echo('共导出'. $recordNum .'条域名记录'. $searStr .''. PHP_EOL . $retStr);
	}
}
?>